<?php
    session_start();
    include("includes/checklogged.php");
    include("includes/mysql_connect.inc.php");
    check_logged();
?>

<?php include('includes/header.php'); ?>
<?php 
  if ($_SESSION["logged"] == "admin"){
    include('includes/nav.php'); 
  }
  else{ 
	include('includes/nav2.php');
}?> 

<div id="content">
</br>
<u>TEST SEARCH </u>
<?php
include ("includes/userfunctions.php");
//=========================================================
if (!isset ($_POST["username"]))
{
   searchbar(EDITVISSUBMITTEXT, SEARCHFUNCTION);
}
else
{
   if (isset ($_POST["username"]))
   {
	    $result=mysql_query("select * from employeelist where First_Name LIKE '%".addslashes($_POST["username"])."%' OR Last_Name LIKE '%".addslashes($_POST["username"])."%'",$link);

   if (!$result)
   {
      die("Mysql Select User DB error...");
   }

   if (mysql_num_rows($result) == 0)
   {
      die("DB Error...");
   }

   $formshow  = '<TABLE BORDER="2" align=center ><TR>';
   $formshow .= '<TD width="10" align=center><b><font color="#1569C7">Emp ID</font></TD>';
   $formshow .= '<TD width="90" align=center><b><font color="#1569C7">First Name</font></TD>';
   $formshow .= '<TD width="90" align=center><b><font color="#1569C7">Last Name</font></TD>';
   $formshow .= '<TD width="250" align=center><b><font color="#1569C7">Address</font></TD>';
   $formshow .= '<TD width="120" align=center><b><font color="#1569C7">Position</font></TD>';
   $formshow .= '<TD width="40" align=center><b><font color="#1569C7">Door #</font></TD></TR>';
   
   while($data=mysql_fetch_array($result,MYSQL_ASSOC))
   {
      $formshow .= '<TR><TD><font face="arial" color="#1569C7" size=2>'.$data["Employee_ID"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["First_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Last_Name"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Address"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Position"].'<font></TD>';
      $formshow .= '<TD><font face="arial" color="#1569C7" size=2>'.$data["Door_No"].'<font></TD></TR>';
   }

   $formshow .= '</TABLE>';
   $formshow .= '<BR><BR><FONT color="red">Total No. of Employees Listed: '.mysql_num_rows($result).'</font></br>';
   $formshow .= '  </br></br><form name="myform" action="empdisplay.php" method="POST">';
   $formshow .= ' <input type="submit" value="Go back"><br>';
   $formshow .= '<table><tr>
	<td align="right" width=650><font size="2" face="MS Sans Serif"><img src="images/printlogo.png" height="20" width="20"><a style="color:#909090" href="javascript:window.print()">print this page</font></a></></td>
	</tr></table>';

   print $formshow;
   }
   else
   {
   searchbar(EDITVISSUBMITTEXT, SEARCHFUNCTION);
   }
}
//=========================================================
?>
</div> <!-- end #content -->

<?php 
  if ($_SESSION["logged"] == "admin"){
    include('includes/sidebar.php'); 
  }
  else{ 
	include('includes/sidebar3.php');
  }?> 
<?php include('includes/footer.php'); ?>
